<?php
class OrderAction extends Action {
    private $delivery = null;
    public function __construct() {
        parent::__construct();
        $this->delivery = new DeliveryModel();
    }

    public function index() {
        parent::page();
        //自动清理尚未重新下单的订单
        $this->model->clearNotReOrder();
        $this->tpl->assign('allOrder',$this->model->findAll());
        $this->tpl->display(SMARTY_ADMIN.'order/show.html');
    }

    public function update() {
        if(isset($_GET['id'])) {
            if(isset($_POST['send'])) {
                $this->model->update() ? $this->redirect->succ(Tool::getPrevPage(),'订单修改成功!') : $this->redirect->error('系统出错，订单修改失败!');
            }
            $this->tpl->assign('oneOrder',$this->model->findOrderDeatails());
            $this->tpl->assign('allDelivery',$this->delivery->findUpdateOrder());
            $this->tpl->display(SMARTY_ADMIN.'order/update.html');
        }

    }

    public function delete() {
        $this->model->delete() ? $this->redirect->succ('?a=order','订单删除成功!') : $this->redirect->error('系统出错，订单删除失败!');
    }

    public function clear() {
        $this->model->clear() ? $this->redirect->succ(Tool::getPrevPage(),'订单清理成功!') : $this->redirect->error('没有找到任何符合清理条件的订单!');
    }


}
?>